-
Notifications
You must be signed in to change notification settings - Fork 147
feat: add support for adding labels to captured errors #1594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for adding labels to captured errors #1594
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maryam-saeidi thanks for your contribution. In addition to my comments I think the only thing left is to update the docs. I've checked and the right place for it is in /docs/reference/agent-api.md
. There is a section with the API description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Could you also add docs for this new option as david pointed out.
@maryam-saeidi what would be the best way to test it locally? |
There is a build error in docs unrelated to this change. However the documentation is rendered properly for the Build error seems to be related to a cross-link refering to the APM server
@colleenmcginnis do you know what might be happening here? is it possible that The error refers to a link
but it was changed in #1592 so maybe there is caching involved? |
It looks like this branch is two commits behind @maryam-saeidi can you catch up your branch to |
We need to build this branch and then link the package in Kibana locally. |
## Summary Updating apm-rum packages mostly to use this feature: elastic/apm-agent-rum-js#1594 Changes |Package|Previous version|Current version|Change log ([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))| |---|---|---|---| |@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to captured errors ([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))| |@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to captured errors ([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))| |@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package @elastic/apm-rum-react|
# Backport This will backport the following commits from `main` to `8.x`: - [Update apm-rum packages (#217800)](#217800) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Maryam Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-10T14:57:06Z","message":"Update apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages mostly to use this feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous version|Current version|Change log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"Update apm-rum packages","number":217800,"url":"https://github.com/elastic/kibana/pull/217800","mergeCommit":{"message":"Update apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages mostly to use this feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous version|Current version|Change log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217800","number":217800,"mergeCommit":{"message":"Update apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages mostly to use this feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous version|Current version|Change log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
Closes elastic/observability-dev#4022 ## Summary In this PR, we are capturing toast errors using apm-rum: https://github.com/user-attachments/assets/b61529f9-ab8e-4171-9042-0884e11eb385 ErrorType is available in labels which this feature was added to the rum agent in this [PR](elastic/apm-agent-rum-js#1594). ### 🧪 How to test Add the following to your kibana.yml file: ``` elastic.apm.active: true elastic.apm.transactionSampleRate: 1.0 elastic.apm.environment: yourName <-- Change to your name ``` <details> <summary>Throw a toast error</summary> Add this code to a page as [alerts page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx) and visit http://localhost:5601/kibana/app/observability/alerts ``` useEffect(() => { const error = new Error('Mary test error > toasts.addError'); toasts.addError(error, { title: 'Testing error toast', toastMessage: error.message }); toasts.addDanger('Testing danger toast'); }, []); ``` </details> Then visit [kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load) filtered for `yourName` in the environment.
## Summary Updating apm-rum packages mostly to use this feature: elastic/apm-agent-rum-js#1594 Changes |Package|Previous version|Current version|Change log ([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))| |---|---|---|---| |@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to captured errors ([elastic#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))| |@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to captured errors ([elastic#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))| |@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package @elastic/apm-rum-react| (cherry picked from commit a616a40) # Conflicts: # package.json
# Backport This will backport the following commits from `main` to `9.0`: - [Update apm-rum packages (#217800)](#217800) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Maryam Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-10T14:57:06Z","message":"Update apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages mostly to use this feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous version|Current version|Change log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0","v9.0.1"],"title":"Update apm-rum packages","number":217800,"url":"https://github.com/elastic/kibana/pull/217800","mergeCommit":{"message":"Update apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages mostly to use this feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous version|Current version|Change log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217800","number":217800,"mergeCommit":{"message":"Update apm-rum packages (#217800)\n\n## Summary \n\nUpdating apm-rum packages mostly to use this feature:\nhttps://github.com/elastic/apm-agent-rum-js/pull/1594\n\n\nChanges\n\n|Package|Previous version|Current version|Change log\n([PR](https://github.com/elastic/apm-agent-rum-js/pull/1599/files))|\n|---|---|---|---|\n|@elastic/apm-rum|^5.16.3|^5.17.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-core|^5.22.1|^5.23.0|add support for adding labels to\ncaptured errors\n([#1594](https://github.com/elastic/apm-agent-rum-js/pull/1594))|\n|@elastic/apm-rum-react|^2.0.5|^2.0.6|version bump only for package\n@elastic/apm-rum-react|","sha":"a616a40f9307cd34c6a28c7192cfee146ca5ad76"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/218145","number":218145,"state":"MERGED","mergeCommit":{"sha":"a32b7835a1c6a2e9aab0cf681a3fd20039eb385c","message":"[8.x] Update apm-rum packages (#217800) (#218145)\n\n# Backport\n\nThis will backport the following commits from `main` to `8.x`:\n- [Update apm-rum packages\n(#217800)](https://github.com/elastic/kibana/pull/217800)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
Closes elastic/observability-dev#4022 ## Summary In this PR, we are capturing toast errors using apm-rum: https://github.com/user-attachments/assets/b61529f9-ab8e-4171-9042-0884e11eb385 ErrorType is available in labels which this feature was added to the rum agent in this [PR](elastic/apm-agent-rum-js#1594). ### 🧪 How to test Add the following to your kibana.yml file: ``` elastic.apm.active: true elastic.apm.transactionSampleRate: 1.0 elastic.apm.environment: yourName <-- Change to your name ``` <details> <summary>Throw a toast error</summary> Add this code to a page as [alerts page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx) and visit http://localhost:5601/kibana/app/observability/alerts ``` useEffect(() => { const error = new Error('Mary test error > toasts.addError'); toasts.addError(error, { title: 'Testing error toast', toastMessage: error.message }); toasts.addDanger('Testing danger toast'); }, []); ``` </details> Then visit [kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load) filtered for `yourName` in the environment. (cherry picked from commit ae9e5d6) # Conflicts: # src/core/packages/notifications/browser-internal/src/toasts/toasts_api.tsx
Closes elastic/observability-dev#4463 ## Summary Since we now have support for error labels in RUM ([PR](elastic/apm-agent-rum-js#1594)), this PR changes the way that we report rum errors to use labels similar to what we've done for toast errors ([PR](#217948)). https://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad ###⚠️ Note In local development, the error is captured twice because react bubbles up the error, but it does not happen in production: ([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats)) > Production and development builds of React slightly differ in the way componentDidCatch handles errors. In development, the errors will bubble up to window, which means that any window.onerror or window.addEventListener('error', callback) will intercept the errors that have been caught by componentDidCatch. In production, instead, the errors will not bubble up, which means any ancestor error handler will only receive errors not explicitly caught by componentDidCatch. ### 🧪 How to test Add the following to your kibana.yml file: ``` elastic.apm.active: true elastic.apm.transactionSampleRate: 1.0 elastic.apm.environment: yourName <-- Change to your name ``` <details> <summary>Throw a fatal react error</summary> Throw an error in the [alerts page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx) and visit http://localhost:5601/kibana/app/observability/alerts </details> Then visit [kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load) filtered for `yourName` in the environment.
Closes elastic/observability-dev#4463 ## Summary Since we now have support for error labels in RUM ([PR](elastic/apm-agent-rum-js#1594)), this PR changes the way that we report rum errors to use labels similar to what we've done for toast errors ([PR](elastic#217948)). https://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad ###⚠️ Note In local development, the error is captured twice because react bubbles up the error, but it does not happen in production: ([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats)) > Production and development builds of React slightly differ in the way componentDidCatch handles errors. In development, the errors will bubble up to window, which means that any window.onerror or window.addEventListener('error', callback) will intercept the errors that have been caught by componentDidCatch. In production, instead, the errors will not bubble up, which means any ancestor error handler will only receive errors not explicitly caught by componentDidCatch. ### 🧪 How to test Add the following to your kibana.yml file: ``` elastic.apm.active: true elastic.apm.transactionSampleRate: 1.0 elastic.apm.environment: yourName <-- Change to your name ``` <details> <summary>Throw a fatal react error</summary> Throw an error in the [alerts page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx) and visit http://localhost:5601/kibana/app/observability/alerts </details> Then visit [kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load) filtered for `yourName` in the environment.
Closes elastic/observability-dev#4463 ## Summary Since we now have support for error labels in RUM ([PR](elastic/apm-agent-rum-js#1594)), this PR changes the way that we report rum errors to use labels similar to what we've done for toast errors ([PR](elastic#217948)). https://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad ###⚠️ Note In local development, the error is captured twice because react bubbles up the error, but it does not happen in production: ([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats)) > Production and development builds of React slightly differ in the way componentDidCatch handles errors. In development, the errors will bubble up to window, which means that any window.onerror or window.addEventListener('error', callback) will intercept the errors that have been caught by componentDidCatch. In production, instead, the errors will not bubble up, which means any ancestor error handler will only receive errors not explicitly caught by componentDidCatch. ### 🧪 How to test Add the following to your kibana.yml file: ``` elastic.apm.active: true elastic.apm.transactionSampleRate: 1.0 elastic.apm.environment: yourName <-- Change to your name ``` <details> <summary>Throw a fatal react error</summary> Throw an error in the [alerts page](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx) and visit http://localhost:5601/kibana/app/observability/alerts </details> Then visit [kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load) filtered for `yourName` in the environment. (cherry picked from commit cea253d)
# Backport This will backport the following commits from `main` to `8.19`: - [Use RUM label for fatal react errors (#218846)](#218846) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Maryam Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-04-29T08:14:48Z","message":"Use RUM label for fatal react errors (#218846)\n\nCloses https://github.com/elastic/observability-dev/issues/4463\n\n## Summary\n\nSince we now have support for error labels in RUM\n([PR](elastic/apm-agent-rum-js#1594)), this PR\nchanges the way that we report rum errors to use labels similar to what\nwe've done for toast errors\n([PR](https://github.com/elastic/kibana/pull/217948)).\n\n\n\nhttps://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad\n\n\n###⚠️ Note\n\nIn local development, the error is captured twice because react bubbles\nup the error, but it does not happen in production:\n([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))\n\n> Production and development builds of React slightly differ in the way\ncomponentDidCatch handles errors. In development, the errors will bubble\nup to window, which means that any window.onerror or\nwindow.addEventListener('error', callback) will intercept the errors\nthat have been caught by componentDidCatch. In production, instead, the\nerrors will not bubble up, which means any ancestor error handler will\nonly receive errors not explicitly caught by componentDidCatch.\n\n### 🧪 How to test\n\nAdd the following to your kibana.yml file:\n\n```\nelastic.apm.active: true\nelastic.apm.transactionSampleRate: 1.0\nelastic.apm.environment: yourName <-- Change to your name\n```\n<details>\n<summary>Throw a fatal react error</summary>\n\nThrow an error in the [alerts\npage](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)\nand visit http://localhost:5601/kibana/app/observability/alerts\n\n</details>\n\nThen visit\n[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)\nfiltered for `yourName` in the environment.","sha":"cea253dcc67ed2cfb460a0707ac1e66cdb9180fa","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"Use RUM label for fatal react errors","number":218846,"url":"https://github.com/elastic/kibana/pull/218846","mergeCommit":{"message":"Use RUM label for fatal react errors (#218846)\n\nCloses https://github.com/elastic/observability-dev/issues/4463\n\n## Summary\n\nSince we now have support for error labels in RUM\n([PR](elastic/apm-agent-rum-js#1594)), this PR\nchanges the way that we report rum errors to use labels similar to what\nwe've done for toast errors\n([PR](https://github.com/elastic/kibana/pull/217948)).\n\n\n\nhttps://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad\n\n\n###⚠️ Note\n\nIn local development, the error is captured twice because react bubbles\nup the error, but it does not happen in production:\n([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))\n\n> Production and development builds of React slightly differ in the way\ncomponentDidCatch handles errors. In development, the errors will bubble\nup to window, which means that any window.onerror or\nwindow.addEventListener('error', callback) will intercept the errors\nthat have been caught by componentDidCatch. In production, instead, the\nerrors will not bubble up, which means any ancestor error handler will\nonly receive errors not explicitly caught by componentDidCatch.\n\n### 🧪 How to test\n\nAdd the following to your kibana.yml file:\n\n```\nelastic.apm.active: true\nelastic.apm.transactionSampleRate: 1.0\nelastic.apm.environment: yourName <-- Change to your name\n```\n<details>\n<summary>Throw a fatal react error</summary>\n\nThrow an error in the [alerts\npage](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)\nand visit http://localhost:5601/kibana/app/observability/alerts\n\n</details>\n\nThen visit\n[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)\nfiltered for `yourName` in the environment.","sha":"cea253dcc67ed2cfb460a0707ac1e66cdb9180fa"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218846","number":218846,"mergeCommit":{"message":"Use RUM label for fatal react errors (#218846)\n\nCloses https://github.com/elastic/observability-dev/issues/4463\n\n## Summary\n\nSince we now have support for error labels in RUM\n([PR](elastic/apm-agent-rum-js#1594)), this PR\nchanges the way that we report rum errors to use labels similar to what\nwe've done for toast errors\n([PR](https://github.com/elastic/kibana/pull/217948)).\n\n\n\nhttps://github.com/user-attachments/assets/87a06ceb-705c-4c6e-ab26-d3e5874fe5ad\n\n\n###⚠️ Note\n\nIn local development, the error is captured twice because react bubbles\nup the error, but it does not happen in production:\n([doc](https://react.dev/reference/react/Component#componentdidcatch-caveats))\n\n> Production and development builds of React slightly differ in the way\ncomponentDidCatch handles errors. In development, the errors will bubble\nup to window, which means that any window.onerror or\nwindow.addEventListener('error', callback) will intercept the errors\nthat have been caught by componentDidCatch. In production, instead, the\nerrors will not bubble up, which means any ancestor error handler will\nonly receive errors not explicitly caught by componentDidCatch.\n\n### 🧪 How to test\n\nAdd the following to your kibana.yml file:\n\n```\nelastic.apm.active: true\nelastic.apm.transactionSampleRate: 1.0\nelastic.apm.environment: yourName <-- Change to your name\n```\n<details>\n<summary>Throw a fatal react error</summary>\n\nThrow an error in the [alerts\npage](https://github.com/elastic/kibana/blob/main/x-pack/solutions/observability/plugins/observability/public/pages/alerts/alerts.tsx)\nand visit http://localhost:5601/kibana/app/observability/alerts\n\n</details>\n\nThen visit\n[kibana-cloud-apm.elastic.dev](https://kibana-cloud-apm.elastic.dev/app/apm/services/kibana-frontend/errors?comparisonEnabled=true&environment=ENVIRONMENT_ALL&kuery=&latencyAggregationType=avg&offset=1d&rangeFrom=now-1h&rangeTo=now&serviceGroup=&transactionType=page-load)\nfiltered for `yourName` in the environment.","sha":"cea253dcc67ed2cfb460a0707ac1e66cdb9180fa"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Maryam Saeidi <[email protected]>
Closes #1591
Summary
This PR allows adding labels to the captureError function, similar to what we have in Node.js agent:
https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-capture-error
Example usage: